package com.mapper;

import com.POJO.GradeRequest;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Package com.mapper
 * @Date 2024-05-23 11:44
 * 成绩修改相关数据库操作
 */
@Mapper
public interface GradeRequestMapper {
    // 根据学生ID获取其所有成绩修改申请
    @Select("SELECT * FROM grade_requests WHERE student_id = #{studentId}")
    List<GradeRequest> getGradeRequestsByStudentId(int studentId);

    // 根据教师ID获取所有待审核的成绩修改申请
    @Select("SELECT * FROM grade_requests WHERE subject_id IN (SELECT subject_id FROM subjects WHERE teacher_id = #{teacherId}) AND status = 'pending'")
    List<GradeRequest> getPendingGradeRequestsByTeacherId(int teacherId);

    // 新增成绩修改申请
    @Insert("INSERT INTO grade_requests (student_id, subject_id, requested_grade, status, reason) VALUES (#{studentId}, #{subjectId}, #{requestedGrade}, 'pending', #{reason})")
    @Options(useGeneratedKeys = true, keyProperty = "requestId")
    void insertGradeRequest(GradeRequest gradeRequest);

    // 更新成绩修改申请状态
    @Update("UPDATE grade_requests SET status = #{status} WHERE request_id = #{requestId}")
    void updateGradeRequestStatus(GradeRequest gradeRequest);

    // 根据申请ID获取成绩修改申请
    @Select("SELECT * FROM grade_requests WHERE request_id = #{requestId}")
    GradeRequest selectGradeRequestById(int requestId);

    // 删除成绩修改申请
    @Delete("DELETE FROM grade_requests WHERE request_id = #{requestId}")
    void deleteGradeRequest(int requestId);
}
